<?php
App::uses('AppModel', 'Model');
/**
 * Login Model
 *
 */
class Login extends AppModel {

	public $actsAs = array();
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'ip' => array(
			'ip' => array(
				'rule' => array('ip'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'succes' => array(
			'boolean' => array(
				'rule' => array('boolean'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	
	public function log($user, $type = 'normal') {
		if(!empty($user) && !empty($user['User']['id'])) {
			$this->save(
				array('Login' => array('user_id' => $user['User']['id'], 'ip' => CakeRequest::clientIP(), 'type' => $type)), 
				array('validate' => false, 'callbacks' => false)
			);
		}
	}
}
